package bdu;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import bdu.test.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * Illustrates JUnit testing of Robocode robots.
 * This test simply verifies that Scavenger is able to beat Walls.
 * @author Bao Huy Ung
 *
 */
public class TestScavengerVersusWalls extends RobotTestBed {

  /**
   * Specifies that Walls and Scavenger are to be matched up in this test case.
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Walls,bdu.Scavenger";
  }
  
  /**
   * This test runs for 10 rounds.
   * @return The number of rounds. 
   */
  @Override
  public int getNumRounds() {
    return 10;
  }
  
  /**
   * The actual test, which asserts that Scavenger has won a majority of rounds against Walls.
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] results = event.getIndexedResults();
    // Sanity check that results[1] is Scavenger (not strictly necessary, but illustrative).
    assertEquals("Check results[1]", results[1].getTeamLeaderName(), "bdu.Scavenger");
    
    // Check to make sure Scavenger won the overall battle.
    assertTrue("Check Scavenger winner", results[1].getRank() == 1);
  }
}
